import { getTime, parseTime } from '../../utils/timeUtil';

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    selectInterviewTimeList:{
      type:Array,
      value:[]
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    interviewTime: [
      {
        name: getTime(Date.now(),1) + '/' + getTime(new Date(),2) && '今天',
        timeStamp: parseTime(Date.now(), '{y}-{m}-{d}'),
        select:false
      },
      {
        name: getTime(Date.now()+86400000,1) + '/' + getTime(Date.now()+86400000,2),
        timeStamp: parseTime(Date.now()+86400000, '{y}-{m}-{d}'),
        select:false
      },
      {
        name: getTime(Date.now()+86400000*2,1) + '/' + getTime(Date.now()+86400000*2,2),
        timeStamp: parseTime(Date.now()+86400000*2, '{y}-{m}-{d}'),
        select:false
      },
      {
        name: getTime(Date.now()+86400000*3,1) + '/' + getTime(Date.now()+86400000*3,2),
        timeStamp: parseTime(Date.now()+86400000*3, '{y}-{m}-{d}'),
        select:false
      },
      {
        name: getTime(Date.now()+86400000*4,1) + '/' + getTime(Date.now()+86400000*4,2),
        timeStamp: parseTime(Date.now()+86400000*4, '{y}-{m}-{d}'),
        select:false
      },
      {
        name: getTime(Date.now()+86400000*5,1) + '/' + getTime(Date.now()+86400000*5,2),
        timeStamp: parseTime(Date.now()+86400000*5, '{y}-{m}-{d}'),
        select:false
      },
      {
        name: getTime(Date.now()+86400000*6,1) + '/' + getTime(Date.now()+86400000*6,2),
        timeStamp: parseTime(Date.now()+86400000*6, '{y}-{m}-{d}'),
        select:false
      },
      {
        name: getTime(Date.now()+86400000*7,1) + '/' + getTime(Date.now()+86400000*7,2),
        timeStamp: parseTime(Date.now()+86400000*7, '{y}-{m}-{d}'),
        select:false
      }
    ],
  },

  lifetimes:{
    ready:function(){
      const selectList = this.data.selectInterviewTimeList;
      const list = this.data.interviewTime;
      selectList.forEach(item1=>{
        list.forEach(item2=>{
          if(item1 == item2.timeStamp){
            item2.select = true;
          }
        })
      });
      this.setData({
        interviewTime:list,
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    selectInterviewTime(e){
      const index = e.currentTarget.dataset.index;
      this.data.interviewTime[index].select = !this.data.interviewTime[index].select;
        this.setData({
          interviewTime:this.data.interviewTime,
      });
    },
  
  
    reset(){
      this.data.interviewTime.forEach(item=>{
        item.select = false;
      });
      this.setData({
        interviewTime:this.data.interviewTime
      })
      this.triggerEvent("interviewTimeListener",{
        interviewTime:[],
        reset:true
      });
    },

    config(){
      let interviewTimeList = this.data.interviewTime.filter((item)=>{
        return item.select;
      }).map(item=>{
        return item.timeStamp;
      });
      
      this.triggerEvent("interviewTimeListener",{
        interviewTime:interviewTimeList,
        reset:false
      });
    }
  }
})
